package com.usian.article.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usian.api.article.AuthorControllerApi;
import com.usian.article.service.impl.AuthorServiceImpl;
import com.usian.model.article.pojos.ApAuthor;
import com.usian.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/api/v1/author")
public class AuthorController implements AuthorControllerApi {
    @Autowired
    private AuthorServiceImpl service;

    @GetMapping("/findByUserId/{id}")
    @Override
    public ApAuthor findByUserId(@PathVariable(name = "id") Integer id) {
        List<ApAuthor> list = service.list(Wrappers.<ApAuthor>lambdaQuery().eq(ApAuthor::getId, id));
        return list.get(0);
    }

    @PostMapping("/save")
    @Override
    public ResponseResult save(ApAuthor apAuthor) {
        apAuthor.setCreatedTime(new Date());
        service.save(apAuthor);
        return service.sucResult;
    }
}
